﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SystemHYS.API.Application.command.ProductionOrdersCommand;
using SystemHYS.Domian.DTO;
using SystemHYS.Domian;
using SystemHYS.API.DTOS;
using SystemHYS.API.Application.command.RawmaterialtestingCommand;

namespace SystemHYS.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RawmaterialtestingController : ControllerBase
    {
        IMediator mediator;
        public RawmaterialtestingController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加原料质检信息
        /// </summary>
        /// <param name="command">生产订单信息</param>、    
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> AddRawmaterialtesting(RawmaterialtestingCreateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 原料质检
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>原料质检信息</returns>
        [HttpGet]
        public async Task<Apiresult<List<Rawmaterialtesting>>> GetRawmaterialtesting([FromQuery]RawmaterialtestingShowCommand command)
        {
            Apiresult<List<Rawmaterialtesting>> apiresult = new Apiresult<List<Rawmaterialtesting>>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 原料信息
        /// </summary>
        /// <param name="command">原料id</param>
        /// <returns>生产订单信息</returns>
        [HttpGet]
        public async Task<Apiresult<RawmaterialtestingDTO>> GetRawmaterialtestingModel([FromQuery] RawmaterialtestingModelCommand command)
        {
            Apiresult<RawmaterialtestingDTO> apiresult = new Apiresult<RawmaterialtestingDTO>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 修改原料信息
        /// </summary>
        /// <param name="command">原料信息</param>、    
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> UpdateRawmaterialtesting(RawmaterialtestingUpdateCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 删除原料信息
        /// </summary>
        /// <param name="command">原料Id</param>
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> DeleteRawmaterialtesting(RawmaterialtestingDeleteCommand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
    }
}
